package mytest.wd;

import cn.hutool.core.lang.hash.Hash;
import com.google.gson.Gson;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import pojo.Phone;
import pojo.Pojo_1;
import pojo.Standard;
import pojo.Usergid;

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class TestJson {

    public static void main(String[] args) throws Exception {
        //本地要读取的excel
        String excelFilePath = "C:\\Users\\86187\\Desktop\\Okash_aa.xlsx";

        //json文件保存的文件路径
        String filePath = "E:\\AfterSchool\\标准化\\json\\sr_json_2025_04_14_3.txt";

        BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
        FileInputStream fileInputStream = new FileInputStream(excelFilePath);
        XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
        int numberOfSheets = workbook.getNumberOfSheets();

        for (int i = 0; i < numberOfSheets; i++) {
            Sheet sheet = workbook.getSheetAt(i);
            switch (sheet.getSheetName()) {
                case "Sheet1":
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        Row row = sheet.getRow(j);
                        Standard standard = new Standard();
                        standard.setUserInfo(String.valueOf(row.getCell(0)));
                        standard.setUserInfoType(String.valueOf(row.getCell(1)));
                        standard.setVendor(String.valueOf(row.getCell(2)));
                        standard.setBizType(String.valueOf(row.getCell(3)));
                        standard.setFlag(String.valueOf(row.getCell(4)));
                        standard.setState(String.valueOf(row.getCell(5)));
                        standard.setBatch(String.valueOf(row.getCell(6) == null ? "" : row.getCell(6)));
                        standard.setTime(String.valueOf(row.getCell(7)));
                        standard.setExtra(String.valueOf(row.getCell(8) == null ? "" : row.getCell(8)));
                        writer.write(new Gson().toJson(standard) + "\r\n");
                    }
                    writer.close();
                    break;
                case "Sheet2" :
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        Row row = sheet.getRow(j);
                        Map<String, Object> hashMap = new LinkedHashMap<>();
                        hashMap.put("ds", String.valueOf(row.getCell(0)));
                        hashMap.put("user_id", String.valueOf(row.getCell(1)));
                        hashMap.put("big_user_gid", String.valueOf(row.getCell(2)));
                        hashMap.put("loan_id", String.valueOf(row.getCell(3)));
                        hashMap.put("group", String.valueOf(row.getCell(4)));
                        hashMap.put("due_dt", String.valueOf(row.getCell(5)));
                        hashMap.put("level", String.valueOf(row.getCell(6)));
                        writer.write(new Gson().toJson(hashMap) + "\r\n");
                    }
                    writer.close();
                    break;
                case "Sheet3":
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        Row row = sheet.getRow(j);
                        Pojo_1 pojo1 = new Pojo_1();
                        pojo1.setUser_gid(String.valueOf(row.getCell(0)));
                        pojo1.setPhone(String.valueOf(row.getCell(1)));
                        writer.write(new Gson().toJson(pojo1) + "\r\n");
                    }
                    writer.close();
                    break;
                case "Sheet4":
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        Row row = sheet.getRow(j);
                        Usergid usergid = new Usergid();
                        usergid.setUserid(String.valueOf(row.getCell(0)));
                        writer.write(new Gson().toJson(usergid) + "\r\n");
                    }
                    writer.close();
                    break;
                case "Sheet5":
                    System.out.println(sheet.getLastRowNum());
                    int k = 0;
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        HashMap<String, Object> hashMap = new LinkedHashMap<>();
                        Row row = sheet.getRow(j);
                        hashMap.put("phone", String.valueOf(row.getCell(0)));
                        writer.write(new Gson().toJson(hashMap) + "\r\n");
                        k++;
                    }
                    writer.close();
                    System.out.println(k);
                    break;
                case "Sheet6":
                    System.out.println(sheet.getLastRowNum());
                    int x = 0;
                    for (int j = 1; j <= sheet.getLastRowNum(); j++) {
                        HashMap<String, Object> hashMap = new LinkedHashMap<>();
                        Row row = sheet.getRow(j);
                        hashMap.put("channel", String.valueOf(row.getCell(2)));
                        hashMap.put("mkt_dt", String.valueOf(row.getCell(1)));
                        writer.write(new Gson().toJson(hashMap) + "\r\n");
                        x++;
                    }
                    writer.close();
                    System.out.println(x);
                    break;
            }
        }

    }

}
